package com.ccx.coachsite.ui.manage;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.ccx.coachsite.R;
import com.ccx.coachsite.bus.Account;
import com.ccx.coachsite.bus.AccountMgr;
import com.ccx.coachsite.ui.own.OwerBaseView;
import com.ccx.coachsite.ui.own.OwerViewKey;

import com.ccx.coachsite.util.Log;
import com.ccx.coachsite.webimage.ImageLoader;

public class MyManageView extends OwerBaseView{
	public static final String TAG = "MyManageView";
	//private TextView lblName, lblphone, lblRole, lblPackage, lblFlow;
	//private ImageView imgStar;

	private View mBtnFriend;
	private View mBtnCollect;
	private View mBtnShare;
	
	private View mBtnCustom;
	private View mBtnGroup;
	private View mBtnSalary;
	private View mBtnSetting;
	private View mBtnMessage;
	private String imgHeader;
	
	public MyManageView(Context context, ManageMainView superView) {
		super(context, superView);
		isRootView = true;
		
		mBtnFriend = findViewById(R.id.btn_ower_friend);
		mBtnFriend.setOnClickListener(new OnFriendListener());
		
		mBtnCollect = findViewById(R.id.btn_ower_collect);
		mBtnCollect.setOnClickListener(new OnCollectListener());
		
		mBtnShare = findViewById(R.id.btn_ower_share);
		mBtnShare.setOnClickListener(new OnShareListener());
		
		mBtnCustom = findViewById(R.id.btn_manage_custom);
		mBtnCustom.setOnClickListener(new OnCustomListener());
		
		mBtnGroup = findViewById(R.id.btn_manage_group);
		mBtnGroup.setOnClickListener(new OnGroupListener());
		
		mBtnSalary = findViewById(R.id.btn_manage_salary);
		mBtnSalary.setOnClickListener(new OnSalaryListener());
		
		mBtnMessage = findViewById(R.id.btn_manage_message);
		mBtnMessage.setOnClickListener(new OnMessageListener());
		
		mBtnSetting = findViewById(R.id.btn_manage_setting);
		mBtnSetting.setOnClickListener(new OnSettingListener());
	
		onLoadSuccess();
	}
	
	class OnFriendListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			SwitchView(OwerViewKey.ll_personal_friend);
		}
	}
	
	class OnCollectListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			SwitchView(OwerViewKey.ll_personal_collect);
		}
	}
	
	class OnShareListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			SwitchView(OwerViewKey.ll_personal_share);
		}
	}
	
	class OnCustomListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			SwitchView(ManageKey.ll_manage_custom);
		}
	}
	
	class OnGroupListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			SwitchView(ManageKey.ll_manage_group);
		}
	}
	
	class OnSalaryListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			Toast.makeText(mContext, "我的薪酬正在建设中，敬请期待……", Toast.LENGTH_SHORT).show();
			//SwitchView(ManageKey.ll_manage_salary);
		}
	}
	
	class OnSettingListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			SwitchView(OwerViewKey.ll_personal_setting);
		}
	}
	
	class OnMessageListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			SwitchView(OwerViewKey.ll_personal_message);
		}
	}

	public void onLoadSuccess() {
		Account account = AccountMgr.readAccountInfo(mContext);
		if(account.getUserId() == -1)
			return ;
		TextView appNum = (TextView) findViewById(R.id.lbl_app_collect_count);
		TextView turNum = (TextView) findViewById(R.id.lbl_tur_collect_count);
		
		appNum.setText("应用收藏: "+account.getOwerAppCollectCount());
		turNum.setText("文章收藏: "+account.getOwerTurCollectCount());
		ImageView imgV =  (ImageView) findViewById(R.id.ower_person_icon);
		
		TextView titleView = (TextView)mSuperView.findViewById(R.id.login_top_title);
		titleView.setText(account.getUsername());
		
		String str = account.getOwerIcon();
		if(imgHeader == null || str == null)
		{
			imgV.setImageResource(R.drawable.ower_image_none);
		}
		
		if(str != null && (imgHeader == null || !imgHeader.equals(str)))
		{
			imgHeader = str;
			ImageLoader.loadBitmap(account.getOwerIcon(), imgV);
		}
		
		/*
		TextView lblName = (TextView) findViewById(R.id.ower_lblName);
		TextView lblphone = (TextView) findViewById(R.id.ower_lblPhone);
		TextView lblRole = (TextView) findViewById(R.id.ower_lblRole);
		ImageView imgStar = (ImageView) findViewById(R.id.ower_imgRank);
		TextView lblPackage = (TextView) findViewById(R.id.ower_taocan);
		TextView lblFlow = (TextView) findViewById(R.id.ower_channel);
		TextView lblFavCount = (TextView) findViewById(R.id.lbl_favour_count);
		TextView lblFriendCount = (TextView) findViewById(R.id.lbl_friend_count);
		
		lblName.setText(account.getUsername());
		lblphone.setText(account.getMobile());
		lblRole.setText(account.getOwerRole());
		lblPackage.setText(account.getOwerPackage());
		lblFlow.setText(account.getOwerFlow());
		lblFavCount.setText(account.getOwerCollectCount()+"");
		lblFriendCount.setText(account.getOwerFriendCount()+"/200");
		
		CommonViewUtils.SetStarImage(account.getOwerStar(), imgStar);
		*/		
		
	}
}